import {createStore,Store } from 'vuex'

import { ComponentCustomProperties } from 'vue'

declare module '@vue/runtime-core' {
  // declare your own store states
  interface State {
    count: number
  }

  // provide typings for `this.$store`
  interface ComponentCustomProperties {
    $store: Store<State>
  }
}

let userStore={
    state:{
        userCount:108,
    },
    mutations:{
        addUserCount(state:any,payload:number){
            return state.userCount+=payload
        }
    }
}

export default createStore({
    state(){
        return {
            count:100
        }
    },
    getters:{
        getCount:(state:any)=>{
             state.count=state.count*10
        }
    },
    mutations:{
        addCount(state,payload:number){
            setTimeout(()=>{
                return state.count+=payload
            },3000)
        }
    },
    actions:{
        addCount(context,payload:number){
            console.log(payload)
            context.commit('addCount',payload)
        }
    },
    modules:{
       user:userStore
    }
})
